package com.wakala.employment.adapter;

import android.text.Html;
import android.view.View;
import android.widget.Button;

import com.wakala.employment.R;
import com.wakala.employment.adapter.base.broccoli.BroccoliRecyclerAdapter;
import com.wakala.employment.adapter.entity.JobInfoVo;
import com.wakala.employment.core.constants.Constants;
import com.wakala.employment.utils.DemoDataProvider;
import com.wakala.employment.utils.PlaceholderHelper;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;

import me.samlss.broccoli.Broccoli;

/**
 * @author xuexiang
 * @since 2019/4/7 下午12:06
 */
public class RecruitManageListAdapter extends BroccoliRecyclerAdapter<JobInfoVo> {
    /**
     * 是否是加载占位
     */
    private boolean mIsAnim;
    private ItemClickListener<JobInfoVo> itemClickListener;

    public RecruitManageListAdapter(boolean isAnim) {
        super(DemoDataProvider.getEmptyJobInfo());
        mIsAnim = isAnim;
    }
    public RecruitManageListAdapter(boolean isAnim,ItemClickListener<JobInfoVo> itemClickListener) {
        super(DemoDataProvider.getEmptyJobInfo());
        mIsAnim = isAnim;
        this.itemClickListener = itemClickListener;
    }


    @Override
    protected int getItemLayoutId(int viewType) {
        return R.layout.adapter_recruit_manage_list_item;
    }

    /**
     * 绑定控件
     *
     * @param holder
     * @param model
     * @param position
     */
    @Override
    protected void onBindData(RecyclerViewHolder holder, JobInfoVo model, int position) {
        holder.text(R.id.tv_title, model.getTitle());
        holder.text(R.id.tv_tag,model.getJobCategoryName());
        holder.text(R.id.tv_summary, Html.fromHtml(model.getContent(),Html.FROM_HTML_MODE_COMPACT));
        holder.text(R.id.tv_praise, model.getPublishTime().substring(0, 16));
        holder.image(R.id.iv_image, model.getUser().getAvatar());
        //holder.text(R.id.tv_location, model.getJobUserAddress().getCity() + model.getJobUserAddress().getDistrict() + model.getJobUserAddress().getDetail());
        Integer jobStatus = model.getStatus();
        Button btn_tv_close = (Button) holder.findView(R.id.tv_close);
        Button btn_tv_edit = (Button) holder.findView(R.id.tv_edit);
        Button btn_tv_refresh = (Button) holder.findView(R.id.tv_refresh);
        Button btn_tv_to_top = (Button) holder.findView(R.id.tv_to_top);
        if(Constants.JOB_STATUS_RUNNING.equals(String.valueOf(jobStatus))){
            //招聘中 显示 关闭职位  修改 刷新 置顶
            holder.text(R.id.tv_status_name, "正在招");
            holder.textColorId(R.id.tv_status_name,R.color.ic_coure_yi_pr);
            //holder.text(R.id.iv_close, "关闭职位");
            btn_tv_close.setVisibility(View.VISIBLE);
            btn_tv_close.setText("关闭职位");
        }else if(Constants.JOB_STATUS_AUTHING.equals(String.valueOf(jobStatus))){
            //审核中 显示  关闭职位和修改
            holder.text(R.id.tv_status_name, "审核中");
            holder.textColorId(R.id.tv_status_name,R.color.color_red);
            btn_tv_refresh.setVisibility(View.GONE);
            btn_tv_to_top.setVisibility(View.GONE);
        }else if(Constants.JOB_STATUS_FINISHED.equals(String.valueOf(jobStatus))){
            //审核中 显示  关闭职位和修改
            holder.text(R.id.tv_status_name, "已招满");
            holder.textColorId(R.id.tv_status_name,R.color.Gray9);
            btn_tv_refresh.setVisibility(View.GONE);
            btn_tv_to_top.setVisibility(View.GONE);
            btn_tv_close.setVisibility(View.GONE);
        }
        //
        holder.click(R.id.tv_close, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClickListener.onItemClick(holder,view,model,position);
            }
        });
    }

    /**
     * 绑定占位控件
     *
     * @param holder
     * @param broccoli
     */
    @Override
    protected void onBindBroccoli(RecyclerViewHolder holder, Broccoli broccoli) {
        if (mIsAnim) {
            broccoli.addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_user_name)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_tag)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_title)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_summary)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_praise)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_comment)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tv_read)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.iv_image)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.btn_link_boss)))
                    .addPlaceholder(PlaceholderHelper.getParameter(holder.findView(R.id.tag_layout)));

        } else {
            broccoli.addPlaceholders(
                    holder.findView(R.id.tv_user_name),
                    holder.findView(R.id.tv_tag),
                    holder.findView(R.id.tv_status_name),
                    holder.findView(R.id.tv_title),
                    holder.findView(R.id.tv_summary),
                    holder.findView(R.id.tv_praise),
                    holder.findView(R.id.tv_comment),
                    holder.findView(R.id.tv_read),
                    holder.findView(R.id.iv_image),
                    holder.findView(R.id.tv_close),
                    //holder.findView(R.id.iv_close),
                    holder.findView(R.id.tv_edit),
                    //holder.findView(R.id.iv_edit),
                    //holder.findView(R.id.iv_refresh),
                    holder.findView(R.id.tv_refresh),
                    //holder.findView(R.id.iv_to_top),
                    holder.findView(R.id.tv_to_top),
                    holder.findView(R.id.btn_link_boss)
            );
        }
    }

}
